package com.ai.module.websocket.coder;

import com.ai.module.business.domain.vo.UserMessage;
import com.alibaba.fastjson2.JSONObject;

import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
import java.nio.ByteBuffer;

/**
 * @author: MrHe
 * @create: 2024-01-27 19:34
 * @description:
 **/

public class UserMessageDecoder implements Decoder.Binary<UserMessage> {
    @Override
    public UserMessage decode(ByteBuffer byteBuffer) throws DecodeException {
        byte[] array = byteBuffer.array();

        return JSONObject.parseObject(byteBuffer.toString(), UserMessage.class);

    }

    @Override
    public boolean willDecode(ByteBuffer byteBuffer) {
        return true;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
